<layout name="Index/header_footer" />
<div class="main-div">
    <form name="main_form" method="POST" action="__SELF__" enctype="multipart/form-data" >
    	<input type="hidden" name="id" value="<?php echo $data['id']; ?>" />
        <table cellspacing="1" cellpadding="3" width="100%">
            <tr>
                <td class="label">角色名称：</td>
                <td>
                    <input  type="text" name="role_name" value="<?php echo $data['role_name']; ?>" />
                </td>
            </tr>
            <tr>
                <td class="label">权限列表：</td>
                <td>
                	<?php foreach ($priData as $k => $v): 
                		if(strpos(','.$pri_id.',', ','.$v['id'].',') !== FALSE)
                			$check = 'checked="checked"';
                		else 
                			$check = '';
                	?>
                    <?php echo str_repeat('-', $v['level'] * 8); ?>
                	<input {$check} level="{$v.level}" type="checkbox" name="pri_id[]" value="{$v.id}" />{$v.pri_name} <br />
                    <?php endforeach; ?>
                </td>
            </tr>
            <tr>
                <td colspan="99" align="center">
                    <input type="submit" class="button" value=" 确定 " />
                    <input type="reset" class="button" value=" 重置 " />
                </td>
            </tr>
        </table>
    </form>
</div>
<script>
// 为所有的选择框绑定点击事件
$(":checkbox").click(function(){
	var cur_level = $(this).attr("level");
	if($(this).attr("checked"))
	{
		var tmplevel = cur_level; 
		var allprev = $(this).prevAll(":checkbox");
		$(allprev).each(function(k,v){
			if($(v).attr("level") < tmplevel)
			{
				tmplevel--; 
				$(v).attr("checked", "checked");
			}
		});
		// 所有子权限也选中
		var allprev = $(this).nextAll(":checkbox");
		$(allprev).each(function(k,v){
			if($(v).attr("level") > cur_level)
				$(v).attr("checked", "checked");
			else
				return false;   
		});
	}
	else
	{
		// 先取出这个复选框所有前面的复选框
		var allprev = $(this).nextAll(":checkbox");
		$(allprev).each(function(k,v){
			if($(v).attr("level") > cur_level)
				$(v).removeAttr("checked");
			else
				return false;  
		});
	}
});
</script>